<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: blog_archiv.php 140 2013-09-22 07:44:23Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 140 $
* 	zuletzt geändert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-22 07:44:23 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

$min = $db->db_query("SELECT
							MIN(DATE_FORMAT(date, '%Y')) as jahr
						FROM
							".TABLE_BLOG_ITEMS."
						WHERE
							status = '2'
						AND
							DATE_FORMAT(date, '%m') != '".date('m')."'
						AND
							language_id = '".intval($_SESSION['languages_id'])."'");

if($min->_numOfRows && !empty($min->fields['jahr'])) {
	$blog_smarty = new smarty;
	$blog_smarty->assign('tpl_path','templates/'.CURRENT_TEMPLATE.'/');
	$blog_smarty->assign('html_tpl_path', CURRENT_TEMPLATE.'/html');
	
	$archiv_array = array();
	for($j = date('Y'); $min->fields['jahr']-1 < $j; $j--) {
		
		$archiv[$j] = array();
		
		for($m = 12; 0 < $m; $m--) {
			$all_mo = array();
			
			if(isset($_GET['m']) && $_GET['m'] == $m) {
				$all_month = $db->db_query("SELECT
												categories_id,
												item_id,
												title
											FROM
												".TABLE_BLOG_ITEMS."
											WHERE
												status = '2'
											AND
												date LIKE '".$j."-".str_pad($_GET['m'], 2, '0', STR_PAD_LEFT)."%'
											AND
												DATE_FORMAT(date, '%m') != '".date('m')."'
											AND
												language_id = '".intval($_SESSION['languages_id'])."'
											ORDER BY
												date DESC");
				
				if($all_month->_numOfRows) {
					
					while(!$all_month->EOF) {
						$all_mo[] = array('title' => $all_month->fields['title'],
											'link' => href_link('blog.php?y='.$j.'&m='.$m.'&blog_cat='.$all_month->fields['categories_id'].'&blog_item='.$all_month->fields['item_id']));
						$total = $count;
						$all_month->MoveNext();
					}
					
					if(!empty($all_mo)) {
						$archiv[$j][$monate[$m]] = array('items' => $all_mo);
						$archiv[$j][$monate[$m]]['active'] = ' class="monat_aktiv"';
						$archiv[$j][$monate[$m]]['total'] = $all_month->_numOfRows;
						$archiv[$j][$monate[$m]]['link'] = href_link('blog.php?y='.$j.'&m='.$m);
					}
				}
				
			} else {
				$all_month = $db->db_query("SELECT
												categories_id,
												item_id,
												title
											FROM
												".TABLE_BLOG_ITEMS."
											WHERE
												status = '2'
											AND
												date LIKE '".$j."-".str_pad($m, 2, '0', STR_PAD_LEFT)."%'
											AND
												DATE_FORMAT(date, '%m') != '".date('m')."'
											AND
												language_id = '".intval($_SESSION['languages_id'])."'");
				if($all_month->_numOfRows) {
					$archiv[$j][$monate[$m]]['total'] = $all_month->_numOfRows;
					$archiv[$j][$monate[$m]]['link'] = href_link('blog.php?y='.$j.'&m='.$m);
				}
			}	
		}
	}
	reset($archiv);
	$blog_smarty->assign('archiv', $archiv);
	$blog_smarty->assign('language', $_SESSION['language']);
	
	if(!CacheCheck()) {
	    $blog_smarty->caching = false;
	    $box_content = $blog_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_blog_archiv.html');
	
	} else {
	  $blog_smarty->caching = true;
	  $blog_smarty->cache_lifetime = CACHE_LIFETIME;
	  $blog_smarty->cache_modified_check = CACHE_CHECK;
	  $cache_id = $_SESSION['language'];
	  $box_content = $blog_smarty->fetch(CURRENT_TEMPLATE.'/boxes/box_blog_archiv.html',$cache_id);
	}
}
?>